﻿<div>
    <Transfer DataSource="_dataSource"
              Disabled="_disabled"
              TargetKeys="_targetKeys.ToArray()"
              SelectedKeys="_selectedKeys"
              Titles="_titles"
              OnChange="OnChange"
              OnScroll="OnScroll"
              OnSelectChange="OnSelectChange">
    </Transfer>

    <Switch Style="margin-top: 16px;" OnChange="OnSwitchChange"></Switch>
</div>

@code {
    private List<TransferItem> _dataSource = new List<TransferItem>();
    private List<string> _targetKeys = new List<string>();
    private string[] _selectedKeys = Array.Empty<string>();
    private string[] _titles = { "Source", "Target" };
    private bool _disabled = false;

    protected override void OnInitialized()
    {
        for (int i = 0; i < 20; i++)
        {
            _dataSource.Add(new TransferItem
            {
                Title = $"Content{i + 1}",
                Description = $"description of content{i + 1}",
                Key = i.ToString(),
                Disabled = i % 3 < 1
            });

            if (i > 10)
                _targetKeys.Add(i.ToString());
        }
        base.OnInitialized();
    }

    private void OnSwitchChange(bool check)
    {
        _disabled = check;
    }

    private OneOf.OneOf<string, RenderFragment> Render(TransferItem item)
    {
        return $"{item.Title} - {item.Description}";
    }

    private void OnChange(TransferChangeArgs e)
    {
        Console.WriteLine(e.Direction);
        Console.WriteLine($"MoveKeys:{string.Join(',', e.MoveKeys)}");
        Console.WriteLine($"TargetKeys:{string.Join(',', e.TargetKeys)}");
    }

    private void OnScroll(TransferScrollArgs e)
    {
        Console.WriteLine(e.Direction);
    }

    private void OnSelectChange(TransferSelectChangeArgs e)
    {
        Console.WriteLine($"SourceSelectedKeys:{string.Join(',', e.SourceSelectedKeys)}");
        Console.WriteLine($"TargetSelectedKeys:{string.Join(',', e.TargetSelectedKeys)}");
    }
}
